package com.hisicom.scqxspxcjc.sceneCheck.resultDecision.service;

import cn.hutool.core.util.ObjectUtil;
import com.hisicom.scqxspxcjc.base.dao.BaseRepository;
import com.hisicom.scqxspxcjc.base.service.BaseService;
import com.hisicom.scqxspxcjc.sceneCheck.resultDecision.domain.ResultDecision;
import com.hisicom.scqxspxcjc.sceneCheck.resultDecision.repostion.ResultDecisionRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhonggls
 * @date 2020/12/21 14:12
 * @Explain
 */
@Service
public class ResultDecisionService implements BaseService<ResultDecision, String> {
    @Autowired
    private ResultDecisionRepository resultDecisionRepository;

    @Override
    public BaseRepository<ResultDecision, String> getRepository() {
        return resultDecisionRepository;
    }

    @Override
    public List<ResultDecision> findAll() {
        return getRepository().findAll(Sort.by(Sort.Direction.fromString("asc"), "sort"));
    }

    public List<ResultDecision> findAllNoId() {
        List<ResultDecision> list = findAll();
        List<ResultDecision> backList = new ArrayList<>();
        if (ObjectUtil.isNotEmpty(list)) {
            list.forEach(resultDecision -> {
                ResultDecision resultDecision1 = new ResultDecision();
                BeanUtils.copyProperties(resultDecision, resultDecision1);
                resultDecision1.setId("");
                backList.add(resultDecision1);
            });
        }
        return backList;
    }
}
